//
//  SettingView.swift
//  ShouChong
//
//  Created by 陈友文 on 2024/7/11.
//

import SwiftUI

struct SettingView: View {
    struct SettingModel:Identifiable {
        var id:String = UUID().uuidString
        var title:String
        var icon:String
    }
    
    @State private var settingList:[SettingModel] = [
        SettingModel(title: "用户中心",icon: "person.fill"),
        SettingModel(title: "数据分析",icon: "doc.text.fill"),
        SettingModel(title: "活跃L友",icon: "person.2.fill"),
        SettingModel(title: "使用日记",icon: "book.closed.fill"),
        SettingModel(title: "使用说明",icon: "questionmark.circle.fill"),
//        SettingModel(title: "系统设置",icon: "gearshape.fill")
    ]
    @AppStorage("user_avator_base64") var avatorBase64 = ""
    @AppStorage("curren_main_color") var currentMainColor = "color_main_01"
    @AppStorage("k_luleme_vip") var lulemeVIP:Bool = false
    var itemClickAction:((_:String) -> Void)
    var body: some View {
        ScrollView {
            HStack {
                Image(uiImage:(avatorBase64.imageFromBase64 ?? UIImage(named: "user_header_01")!))
                    .resizable()
                    .aspectRatio(contentMode: .fill)
                    .frame(width:100,height: 100)
                    .cornerRadius(50)
                    .overlay(alignment: .bottomTrailing) {
                        if lulemeVIP {
                            Image("icon_vip")
                                .resizable()
                                .aspectRatio(contentMode: .fill)
                                .frame(width: 16,height: 16)
                                .offset(x:4,y:4)
                        }
                    }
                Spacer()
            }
            .padding(.horizontal,50)
            .padding(.bottom,30)
            .onTapGesture {
                self.itemClickAction("用户中心")
            }

            
            ForEach(settingList) { item in
                HStack {
                    Image(systemName:item.icon)
                        .resizable()
                        .aspectRatio(contentMode: .fit)
                        .frame(width: 20,height: 20)
                        .foregroundColor(Color(currentMainColor))
                    Text(item.title)
                        .modifier(MainTextModifier(fontSize: 16, fontWeight: .medium, foreColor: Color("color_text_black")))
                    Spacer()
                }.padding(.horizontal,20)
                    .padding(.vertical,16)
                    .onTapGesture {
                        self.itemClickAction(item.title)
                    }
            }
        }
    }
}

